package com.cndw.kungfu.model.activity.domain;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.cndw.kungfu.config.ConstantsConfig;
import com.cndw.kungfu.ext.LogUtil;
import com.cndw.kungfu.ext.StringProcesser;
import com.cndw.kungfu.ext.XmlProcesser;

/**
 * 宝箱开启的配置实体类
 * 
 * @author fantadust [9677889@qq.com]
 * @date 2012-1-11 下午6:16:21
 */
public class RateChest {

	private static final Map<Integer, RateChest> commData = new HashMap<Integer, RateChest>();
	/**
	 * 道具id
	 */
	private int goodsId;
	/**
	 * 需要的金币
	 */
	private int gold;
	/**
	 * 名称
	 */
	private String name;
	/**
	 * 子物品名称
	 */
	private String nameList;
	/**
	 * 奖励道具id
	 */
	private String awardList;
	/**
	 * 奖励道具几率
	 */
	private String rateList;
	/**
	 *  个数列表
	 */
	private String numList;
	/**
	 * 是否绑定
	 */
	private int bind;
	/**
	 * 道具id数组
	 */
	private int[] awards;
	/**
	 * 几率数组
	 */
	private int[] rates;
	/**
	 * 个数数组
	 */
	private int[] nums;

	public int getGoodsId() {
		return goodsId;
	}

	public void setGoodsId(int goodsId) {
		this.goodsId = goodsId;
	}

	public int getGold() {
		return gold;
	}

	public void setGold(int gold) {
		this.gold = gold;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getNameList() {
		return nameList;
	}

	public void setNameList(String nameList) {
		this.nameList = nameList;
	}

	public String getAwardList() {
		return awardList;
	}

	public void setAwardList(String awardList) {
		this.awardList = awardList;
	}

	public String getRateList() {
		return rateList;
	}

	public void setRateList(String rateList) {
		this.rateList = rateList;
	}

	public int getBind() {
		return bind;
	}

	public void setBind(int bind) {
		this.bind = bind;
	}

	public int[] getAwards() {
		return awards;
	}

	public int[] getRates() {
		return rates;
	}
	

	public String getNumList() {
		return numList;
	}

	public void setNumList(String numList) {
		this.numList = numList;
	}

	public int[] getNums() {
		return nums;
	}


	static {
		load();
	}

	private static final String configFile = "rateChest.xml";

	public static synchronized void load() {
		String fileName = ConstantsConfig.getLocaleResource() + configFile;
		List<RateChest> chestList = XmlProcesser.processXml(RateChest.class, fileName);
		for (RateChest e : chestList) {
			e.awards = StringProcesser.toIntArray(e.awardList);
			e.rates = StringProcesser.toIntArray(e.rateList);
			if (e.numList != null ) {
				e.nums = StringProcesser.toIntArray(e.numList);
				if (e.awards.length != e.nums.length) {
					LogUtil.getMain().error("rateChest err nums " + e.goodsId);
				}
			}

			if (e.awards.length != e.rates.length) {
				LogUtil.getMain().error("rateChest err " + e.goodsId);
			}
			commData.put(e.getGoodsId(), e);
		}
	}

	public static RateChest getRateChest(int goodsId) {
		return commData.get(goodsId);
	}

}
